package cn.javass.dp.strategy.selfexample;

/**
 * Strategy层为Context定义
 * Created by wanggen on 19/7/25.
 */
public class CashContext {

    CashSuper cs = null;

    //根据条件返回相应的对象
    public CashContext(int type) {
        switch (type) {
            case 1:
                //正常收费
                CashNormal cs0 = new CashNormal();
                cs = cs0;
                break;
            case 2:
                //满300返100
                CashReturn cr1 = new CashReturn(300, 100);
                cs = cr1;
                break;
            case 3:
                //打8折
                CashRebate cr2 = new CashRebate(0.8);
                cs = cr2;
                break;
        }
    }

    public double GetResult(double money) {
        return cs.acceptCash(money);
    }
}
